﻿using Shop.DB;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Shop.Application.Common
{
    public class CreateName
    {
        /// <summary>
        /// 创建订单名称
        /// </summary>
        /// <param name="context"></param>
        /// <param name="num"></param>
        /// <returns></returns>
        public static string CreateOrderName(DBContext context,int num)
        {
            var chars = "ABCDEFGHIJKL123456MNOPQRSTUVWXYZ7opqrstuvwx890abcdefghijklmnyz";
            var result = new char[6];
            var random = new Random();

            do
            {
                for (int i = 0; i < result.Length; i++)
                {
                    result[i] = chars[random.Next(chars.Length)];
                }
            } while (context.Orders.Any(x => x.OrderName == new string(result)));

            return new string(result);
        }
    }
}
